<template>
   <div class="login">
      <div class="con">
          <h3 class="text-primary text-center h1">登录</h3>
          <el-input v-model="user.username" placeholder="请输入账号" clearable></el-input>
          <el-input v-model="user.password" placeholder="请输入密码" clearable show-password></el-input>
          <div class="text-center">
              <el-button type="primary" @click="login">登录</el-button>
          </div>
      </div>
  </div>
</template>
<script>
import {requserlogin} from '../../http/api'
import { mapGetters, mapActions } from "vuex";
export default {
    data() {
        return {
             user:{
            username:"",
            password:""
          }
        }
    },  
       
    
    computed:{
        // 获取getters中的属性 getname age arr 这样就不用写"$store.getters直接可以直接从getters中获取数据
          ...mapGetters({})
    },
    methods: {
        //获取actions中的方发 "changename",'changearr' 这样可以在调用actions方法去通知metatios中的方法修改status数据就可以不用写$store.disparch
        ...mapActions({ 
            changeUserinfo:"changeUserinfo"
            }),
        // 登录
        login(){
         requserlogin(this.user).then(res=>{
            console.log(res);
            if(res.data.code=200){
                // 存储res.data.list
            this.changeUserinfo(res.data.list)
            this.$router.replace("/")
            }
         })

        },

    },

    
}
</script>
<style lang="less" scoped>
@import "../../less/index.less";
.login{
    width: 100vw;
    height: 100vh;
    background: linear-gradient(to right,@primary-light,@primary,@primary-deep);
    .con{
        padding: @padding;
        width: 300px;
        background: @white;
        position: fixed;
        left: 50%;
        top: 50%;
        transform: translate(-50%,-50%);
        border-radius: @border;
    }
    h3{
        margin-bottom:@margin;
    }
    .el-input{
         margin-bottom:@margin;
    }
}
</style>